<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/11/9
  Time: 14:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    点赞的次数: <span id="s1">0</span>
    <br>
    <button onclick="fun1()">点赞</button>
</body>
</html>
<script>
    //点击事件
    function fun1() {
        //获取span标签的文本值
        var number = document.getElementById("s1").innerText;
        //请求后台
        //1、创建核心对象
        var xhr = new XMLHttpRequest();
        //调用open方法   get请求   请求的地址
        xhr.open("get","demo07Servlet?number=" + number);
        //发送请求
        xhr.send();
        //当xhr的状态改变 调用匿名函数      4 数据返回回来
        xhr.onreadystatechange = function() {
            if(xhr.readyState == 4) {
                //拿到响应的数据
                var n = xhr.responseText;
                document.getElementById("s1").innerText = n;
            }
        }

    }
</script>
